﻿@page "/check"
@page "/check/{ForceConfirm}"
@layout StudentLayout
@inject StudentClient Http
@inject ConfirmService ConfirmService

<PageTitle>住宿信息核对</PageTitle>

@if (@loading)
{
    <p>Loading...</p>
}
@if(@BedData is null || !string.IsNullOrEmpty(ForceConfirm))
{
    if (@hasDoom is null)
    {
        <Breadcrumb Style="margin:2vh;" Separator=">">
		<BreadcrumbItem Href="/login/student">学生登录</BreadcrumbItem>
		<BreadcrumbItem Href="/StudentProfile">检查信息</BreadcrumbItem>
		<BreadcrumbItem>二次确认</BreadcrumbItem>
	    </Breadcrumb>
        <Alert Type="@AlertType.Warning"
               Message="请进行二次确认"
               Description="请确认在校内是否有宿舍"
               Style="margin:2vh 0;"
               ShowIcon="true"/>
        <div style="width:100%;display:flex;flex-direction:row;justify-content:center;">
        <Button Style="margin:1vw;"
                Type=@ButtonType.Primary @onclick="@(()=>hasDoom = true)">有宿舍</Button>
        <Button Style="background-color: rgb(220,20,60);margin:1vw;" 
                Type=@ButtonType.Primary @onclick="@(()=>hasDoom = false)">无宿舍</Button>
        </div>
    }
    else if (@hasDoom == true && !(BedData is null))
    {
        <UpdateDoom Doom=@BedData ForceConfirm />
    }
    else if (@hasDoom == true)
    {
        <UpdateDoom />
    }
    else
    {
        <UpdateHotel />
    }
}
else
{
    <UpdateDoom Doom=@BedData />
}

@code {
    [Parameter]
    public string? ForceConfirm { get; set; }
    private Bed? BedData;
    private bool loading = true;

    private bool? hasDoom = null;

    protected async override Task OnInitializedAsync()
    {
        BedData = await Http.GetBed();
        loading = false;
    }
}
